<?php

namespace addons\cloud_market\utils;

use EasyWeChat\Factory;
use EasyWeChat\Payment\Application;
use think\facade\Env;

class Wechat
{
    public $config = [
        // 必要配置
        'app_id'     => 'wx71ea3f3257f64424',
        'mch_id'     => '1524017371',
        'key'        => '8934e7d15453e97507ef794cf7b0519d',   // API 密钥
        // 如需使用敏感接口（如退款、发送红包等）需要配置 API 证书路径(登录商户平台下载 API 证书)
        //        'cert_path' => 'path/to/your/cert.pem', // XXX: 绝对路径！！！！
        //        'key_path'  => 'path/to/your/key',      // XXX: 绝对路径！！！！
        'notify_url' => 'http://dev_api.dkyx.cc/order/notify_wechat',     // 你也可以在下单时单独设置来想覆盖它
    ];
    /**
     * @var Application
     */
    private $app;

    public function __construct()
    {
        $this->config['notify_url'] = "http://api.dkyx.cc/api.order/notify_wechat";
        $this->init();
    }

    /**
     * @return $this
     */
    public function init()
    {
        $this->app = Factory::payment($this->config);
        return $this;
    }

    /**
     * @return Application
     */
    public function getApp(): Application
    {
        return $this->app;
    }
}
